<template>
  <div class="main">
    <PureTableBar title="客户评分列表" class="list_hei">
      <template #buttons>
        <el-button type="primary" @click="customerVisible = true"> 客户评分 </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" size="small"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination"
          @size-change="handleSizeChange" @current-change="handleCurrentChange" :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }">
          <template #operation="{ row }">
            <el-button type='primary' text @click="CheckCreditReport(row)">
              查看评分结果
            </el-button>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
    <ReDialog :width="550" :height="250" :models="customerVisible" @Closes="cancelCustomerRating()">
      <template #header>
        <h2 style="text-align: center;">客户评分</h2>
      </template>
      <template #main>
        <el-form :model="customerRatingForm" label-width="150px" label-position="right" style="width: 80%; margin: 0 auto"
          ref="customerForm" :rules="rule">
          <el-form-item label="接入数据名称" prop="apiInfoDataShareId">
            <el-select v-model="customerRatingForm.apiInfoDataShareId" placeholder="接入数据名称" clearable>
              <el-option v-for="item in selectData.accessDataList" :key="item.selectId" :label="item.selectName"
                :value="item.selectId" />
            </el-select>
          </el-form-item>
          <el-form-item label="指数体系名称" prop="portraitIndexSystemId">
            <el-select v-model="customerRatingForm.portraitIndexSystemId" placeholder="请选择类型" clearable>
              <el-option v-for="item in selectData.indexSystemList" :key="item.selectId" :label="item.selectName"
                :value="item.selectId" />
            </el-select>
          </el-form-item>
          <el-form-item label="评分规则" prop="scoringRules">
            <el-select v-model="customerRatingForm.scoringRules" placeholder="请选择类型" clearable>
              <el-option v-for="item in selectData.scoreRuleList" :key="item.selectId" :label="item.selectName"
                :value="item.selectId" />
            </el-select>
          </el-form-item>
        </el-form>
      </template>
      <template #footer>
        <span style="display: block;margin: 0 auto; width: 30%;">
          <el-button @click="saveCustomerRating(customerForm)" :loading="BtnLoading" type="primary">保存</el-button>
          <el-button @click="cancelCustomerRating()">
            取消
          </el-button>
        </span>
      </template>
    </ReDialog>
    <ReDialog :width="1000" :height="500" :models="resultVisible" @Closes="resultVisible = false">
      <template #header>
        <h2 style="text-align: center;">客户评分详情</h2>
      </template>
      <template #main>
        <PureTableBar title="客户评分结果列表" class="list_hei">
          <template v-slot="{ size, checkList }">
            <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading"
              size="small" :data="resultList" :columns="resultColumn" :checkList="checkList" :pagination="pagination1"
              @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :header-cell-style="{
                background: 'var(--el-table-row-hover-bg-color)',
                color: 'var(--el-text-color-primary)'
              }">
            </pure-table>
          </template>
        </PureTableBar>
      </template>
    </ReDialog>
  </div>
</template>
<script setup lang = "ts" >
import { PureTableBar } from "@/components/RePureTableBar";
import { useCommon } from "./hook/customerRating";
import { ref } from "vue";
const customerForm = ref();
const {
  customerVisible,
  customerRatingForm,
  rule,
  selectData,
  loading,
  columns,
  resultColumn,
  dataList,
  pagination,
  pagination1,
  resultVisible,
  resultList,
  BtnLoading,
  CheckCreditReport,
  saveCustomerRating,
  cancelCustomerRating,
  handleCurrentChange,
  handleSizeChange,
  handleSizeChange1,
  handleCurrentChange1,
} = useCommon()
</script>

<style scoped>
@import url(@/style/CreditComm.scss);

.main {
  height: calc(100% - 25px);
}

.top {
  display: flex;
  justify-content: space-between;
}

.top-left {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
